<?php
class OfficeDivs {
	
	public static function userMenu(Profile $profile) {
	
		echo "<div class=\"userMenu\">";
		echo "<a href=\"office.php?action=profile_active\">";
		echo '<img alt="profile_icon" src="images/profile_icon.png" width="25%" height="80%" id="profile"
				onmouseover="onImageHover(this)" onmouseout="onImageHover(this)"> Профил';
		echo "</a>";
		echo "</div>";
		echo "<div class=\"userMenu\">";
		echo "<a href=\"office.php?action=mail_active\">";
		echo '<img alt="mail_icon" src="images/mail_icon.png" width="25%" height="80%" id="mail"
				onmouseover="onImageHover(this)" onmouseout="onImageHover(this)"> Съобщения';
		echo "</div>";
		echo "<div class=\"userMenu\">";
		echo "<a href=\"office.php?action=ranklist_active\">";
		echo '<img alt="ranklist_icon" src="images/ranklist_icon.png" width="25%" height="80%" id="ranklist"
				onmouseover="onImageHover(this)" onmouseout="onImageHover(this)"> Класация';
		echo "</div>";
	
		echo "<div id=\"logout\">";
		echo "<a href=\"office.php?action=logout\">Изход</a>";
		echo "</div>";
	
	}
	
	public static function statsMenu(Profile $profile) {
	
		$user = $profile->getUser();
		echo "<table class=\"statsMenu\"><tr>";
		echo "<td> Ниво: ".$user->getLevel()."</td>";
		echo '<td><img alt="health_icon" src="images/health_icon.png" width="30" height="25" id="health">';
		echo $user->getHealth()."</td>";
		echo '<td><img alt="exp_logo" src="images/exp_logo.png" width="30" height="25" id="exp">';
		echo $user->getExperience()."</td>";
		echo '<td><img alt="energy_logo" src="images/energy_logo.png" width="30" height="25" id="energy">';
		echo $user->getEnergy()."</td>";
		echo '<td><img alt="money_logo" src="images/money_logo.png" width="30" height="25" id="money">';
		echo $user->getMoney()."</td>";
		echo '<td><img alt="attack" src="images/attack.png" width="30" height="25" id="attack">';
		echo $user->getAttack()."</td>";
		echo '<td><img alt="defence" src="images/defence.png" width="30" height="25" id="defence">';
		echo $user->getDefence()."</td>";
		echo '<td><img alt="rank" src="images/wins-losses.png" width="30" height="25" id="rank">';
		echo $user->getRank()."% </td>";
		echo "</tr></table>";
		
	}
	
	public static function profileDiv(Profile $profile, $request) {
		
		if(isset($request['profile'])) {
			
			$viewProfile = new Profile($request['profile']);
		
		
			if ($profile->getUsername() != $viewProfile->getUsername()) {
				
				$help = $profile;
				$profile = $viewProfile;
				$viewProfile = $help;
			}
		
		}
		$profilePic;
		if($profile->getProfilePic() == null) {
			
			$profilePic = "default_picture.png";
		} else {
			
			$profilePic = $profile->getProfilePic();
		}
		echo "<form method=\"POST\" action=\"office.php?action=edit_profile_active\">";
		echo "<table class=\"profileView\">";
		echo "<tr>";
		echo "<td rowspan=5><img width=\"200px\" src=\"uploads/".$profilePic."\" /></td>";
		echo "<td>".$profile->getUsername()."</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td>Име: ".$profile->getFirstName()."</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td>Фамилия: ".$profile->getLastName()."</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td>Е-mail: ".$profile->getEmail()."</td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td>Статус: ".$profile->getStatus()."</td>";
		echo "</tr>";
		
		if (!isset($request['profile'])) {
			
			echo "<tr>";
			echo "<td colspan=\"2\"><button name=\"edit\" id=\"edit\">Редактирай профила</button></td>";
			echo "</tr>";
		
		}
		echo "</table>";
		echo "</form>";
	}
	
	public static function slaveMarketDiv(Profile $profile,$request) {
	
		echo "<p>Здравей, ". $profile->getUsername() ."! </p>";
		if(isset($request['unit_id'])) {
			
			OfficeForms::slaveMarketForm($profile, $request);
			
		} else {
			echo "<table class=\"unitsMarket\">";
			echo "<tr>";
			echo "<td colspan=\"4\">";
			echo "Наеми си програмисти";
			echo "</td>";
			echo "</tr>";
			echo "<tr>";
				
			$logos = array(
						
					"1" => "php",
					"2" => "javascript",
					"3" => "c++",
					"4" => "java"
				
			);
				
			foreach ($logos as $key => $value) {
			
				echo '<td><a href="office.php?action=slave_market_active&unit_id='.$key.'">';
				echo '<img alt="'.$value.'_logo" src="images/'.$value.'_logo.png" width="130" height="150" id="'.$value.'"
						onmouseover="onImageHover(this)" onmouseout="onImageHover(this)">';
				echo "</a></td>";
			}
				
			echo "</tr>";
			echo "</table>";
		}
	}
	
	public static function compBattleDiv(Profile $profile, $request) {
		
		echo "<p>Здравей, ". $profile->getUsername() ."!</p>";
		if($profile->getUser()->getCompBattles() > 1) {
			
		echo "<p>Остават ти още ". $profile->getUser()->getCompBattles() ." опита за днес!</p>";
		
		} else if($profile->getUser()->getCompBattles() == 1) {
			
			echo "<p>Остава ти още ". $profile->getUser()->getCompBattles() ." опит за днес!</p>";
			
		} else if($profile->getUser()->getCompBattles() <=0 ) {
			
			echo '<p class="error" >Нямаш повече опити за днес!<p>';
		}
		
		OfficeForms::compBattleForm($profile, $request);
	}
	
	public static function emptyPocketsDiv(Profile $profile, $request) {
		
		echo "<p>Здравей, ". $profile->getUsername() ."! </p>";
		
		if(isset($request['getQuestion']) || isset($request['question'])) {
			
			OfficeForms::emptyPocketsForm($profile, $request);
			
		} else {
			
			if($profile->getUser()->getQuestionsReset() == 0) {
				
				echo "<p>Свърши парите? Можеш да натрупаш малко капитал като ни отговриш на 1 въпрос :)</p>";
				echo "<p>Не забравяй обаче, че имаш само по един опит на ден!</p>";
				echo "<form method=\"POST\" action=\"office.php?action=empty_pockets_active&question\">";
				echo '<button id="getQuestion" name="getQuestion" class="button">Изтегли въпрос!</button>';
				echo "</form>";
			} else {
				
				echo '<p class="error">Нямаш повече опити за днес :)</p>';
			}
		
		}
	}
	
	public static function beerDispDiv(Profile $profile, $request) {
		
		if ($profile->getUser()->checkIfLocked()) {
			
			header("Location: beerWorld.php");
			
		}  else {
		if(isset($request['beers'])) {
			
			Utils::recharge($profile, $request);
			
		} else {
				//echo '<div class="close"><img class="close" alt="close" src="images/close.png"></div>';
				echo "<p>Здравей, ". $profile->getUsername() ."!</p>";
				echo "<p>Нямаш достатъчно енергия, за да дразниш колегите?</p>";
				echo "<p>Пийни една бира... или две... или три...</p>";
				echo "<p>Но не забравяй, че докато си в бирарията, няма да можеш да правиш нищо друго.</p>";
				
				echo "<table id=\"drinkBeer\">";
				echo "<tr>";
				
				$logos = array(
				
						"1" => "1",
						"2" => "2",
						"3" => "3",
				
				);
				
				foreach ($logos as $key => $value) {
						
					echo '<td><a href="office.php?action=beer_disp_active&beers='.$key.'">';
					echo '<img alt="'.$value.'_logo" src="images/beer_'.$value.'.png" width="150px" height="150px" id="'.$value.'"
								onmouseover="onImageHover(this)" onmouseout="onImageHover(this)">';
					echo "</a></td>";
				}
				echo "</tr>";
				echo "<tr><td>1 бира (45 мин.) = 2 енергия. </td><td>2 бири (1ч 20 мин) = 4 енергия.</td><td>3 бири (2 часа) = 6 енергия.</td></tr>";
				echo "</table>";
				
			}
		}
	}
	
	public static function ranklistDiv(Profile $profile, $request) {
		
		if(isset($request['profile'])) {
			
			OfficeDivs::profileDiv($profile, $request);
			
		} else {
			$profiles = DBUtils::getProfiles();
		
			echo '<p> Класация </p> 
				<table class="section">
				<tr>
					<th> N: </th>
					<th> Username: </th>
					<th> Победи: </th>
					<th> Загуби: </th>
				</tr>';
			
			for ($i = 1; $i < sizeof($profiles); $i++) {
				
				echo '<tr>
					  <td>'.($i).'</td>
					  <td><a href="office.php?action=ranklist_active&profile='.$profiles[$i]['user_name'].'">'.$profiles[$i]['user_name'].'</a></td>
					  <td>'.$profiles[$i]['wins'].'</td>
					  <td>'.$profiles[$i]['looses'].'</td>';
			}
			
			echo '</tr></table>';
		
		}
		
	}
	
	public static function battleDiv(Profile $profile, $request) {
		
		if(isset($request['profile'])) {
			
			$def = new Profile($request['profile']);
			Battle::createBattle($profile->getUser(), $def->getUser());
		} else {
			$user = $profile->getUser();
			$profiles = DBUtils::getProfilesByLevel($user->getLevel());
			echo '<p> Избери колега: </p> 
				  <table class="section">
					<tr>
						<th> Username: </th>
						<th> Победи: </th>
						<th> Загуби: </th>
					</tr>';
				
			for ($i = 0; $i < sizeof($profiles); $i++) {
			
				if($profiles[$i]['user_name'] != $user->getUsername() && $profiles[$i]['user_name'] != "Компютъра") {
					echo '<tr>
						  <td>'.$profiles[$i]['user_name'].'</a></td>
						  <td>'.$profiles[$i]['wins'].'</td>
						  <td>'.$profiles[$i]['looses'].'</td>
						  <td><a href="office.php?action=battle_active&profile='.$profiles[$i]['user_name'].'">Хакни</td>';
				}
			}
				
			echo '</tr></table>';
		}
		
	}
}
